package com.example.controller;
import com.example.Service.SocialMemoService;
import com.example.entity.SocialMemo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/social")
@CrossOrigin(origins = "*")
public class SocialMemoController {

    @Autowired
    private SocialMemoService socialMemoService;

    @PostMapping("/add")
    public String addMemo(@RequestBody SocialMemo memo) {
        return socialMemoService.addMemo(memo) > 0 ? "success" : "fail";
    }

    @DeleteMapping("/delete/{memoId}")
    public String deleteMemo(@PathVariable Integer memoId) {
        return socialMemoService.deleteMemoById(memoId) > 0 ? "success" : "fail";
    }

    @PutMapping("/update")
    public String updateMemo(@RequestBody SocialMemo memo) {
        return socialMemoService.updateMemo(memo) > 0 ? "success" : "fail";
    }

    @GetMapping("/user/{userId}")
    public List<SocialMemo> getMemosByUserId(@PathVariable Integer userId) {
        return socialMemoService.getMemosByUserId(userId);
    }
}
